package org.eerbaar.parser.core.exe.impl;

import java.util.ArrayList;
import java.util.List;

import org.eerbaar.parser.core.def.Symbol;
import org.eerbaar.parser.core.def.impl.DefaultSymbol;
import org.eerbaar.parser.core.exe.SymbolInstance;

public class DefaultSymbolInstance
    extends DefaultSymbol
    implements SymbolInstance {

    private final List<Symbol> children = new ArrayList<Symbol>();
    private final int end;
    private final int start;

    public DefaultSymbolInstance(String name) {
        this(name, 0, 0);
    }

    public DefaultSymbolInstance(String name, int start, int end) {
        super(name);
        this.start = start;
        this.end = end;
    }

    public DefaultSymbolInstance(Symbol symbol, Symbol child, int start, int end) {
        super(symbol.getName());
        this.children.add(child);
        this.start = start;
        this.end = end;
    }

    public DefaultSymbolInstance(Symbol symbol, SymbolInstance c1,
            SymbolInstance c2) {
        super(symbol.getName());
        this.children.add(c1);
        this.children.add(c2);
        start = c1.getStart();
        end = c2.getEnd();
    }

    @Override
    public Symbol[] getChildren() {
        return children.toArray(new Symbol[] {});
    }

    @Override
    public int getEnd() {
        return end;
    }

    @Override
    public int getStart() {
        return start;
    }

    @Override
    public String toString() {
        return super.toString() + "[" + start + "," + end + "]";
    }
}
